﻿using HuiZe.education.Common;
using HuiZe.education.ViewModel;
using PropertyChanged;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using YuanCode.Control.Controls;

namespace HuiZe.education.View
{
    /// <summary>
    /// PersonCenterView.xaml 的交互逻辑
    /// </summary>
    /// 
    [AddINotifyPropertyChangedInterface]
    public partial class PersonCenterView : UserControl
    {
        private Button getValidationCodeBtn;
        private Button getValidationCodeBtn2;
        private Button getValidationCodeBtn3;
        private Button getValidationCodeBtn4;
        private Button getValidationCodeBtn5;
        PersonCenterViewModel personViewModel1 { get; set; }
        public PersonCenterView()
        {

            InitializeComponent();

            Loaded += PersonCenterView_Loaded;
        }

        private void PersonCenterView_Loaded(object sender, RoutedEventArgs e)
        {
            msgBox2.Visibility = Visibility.Visible;
            msgBox2.Visibility = Visibility.Hidden;
            msgBox.Visibility = Visibility.Visible;
            msgBox.Visibility = Visibility.Hidden;

            sjbdmsgBox.Visibility = Visibility.Visible;
            sjbdmsgBox.Visibility = Visibility.Hidden;

            name.SelectionStart = name.Text.Length;
            var personCenterViewModel = DataContext as PersonCenterViewModel;

            personCenterViewModel.personCenterView = this;
            personViewModel1 = personCenterViewModel;
            personCenterViewModel.LoadData();
            KMComBox.subjectIds = personViewModel1.user.subject_id;
            treeView.gradeIds = personViewModel1.user.grades_ids;
            treeView.ClassIds = personViewModel1.user.class_ids;
            //treeView.Grades = personViewModel1.Grades;
            if (personCenterViewModel.user.qq != null && personCenterViewModel.user.qq != "")
            {
                QQjb.Content = "解绑";
            }
            else
            {
                QQjb.Content = "绑定";
            }

            if (personCenterViewModel.user.wx != null && personCenterViewModel.user.wx != "")
            {
                WXjb.Content = "解绑";
            }
            else
            {
                WXjb.Content = "绑定";
            }

            if (personCenterViewModel.user.mobile != null && personCenterViewModel.user.mobile != "")
            {
                SJjb.Content = "解绑";
            }
            else
            {
                SJjb.Content = "绑定";
            }

            //KMComBox;
            //treeView;



        }

        private void hideBoxBtn_Click(object sender, RoutedEventArgs e)
        {
            msgBox.Visibility = Visibility.Collapsed;
        }

        private void treeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
        {
            var personCenterViewModel = DataContext as PersonCenterViewModel;
            personCenterViewModel.SelectClass(e.NewValue);
        }

        private void treeView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var personCenterViewModel = DataContext as PersonCenterViewModel;
            var list = treeView.ItemsSource;

        }

        private void YCButton_Click(object sender, RoutedEventArgs e)
        {


        }

        private void YCWateTextBox_GotFocus(object sender, RoutedEventArgs e)
        {
            //PersonCenterViewModel PersonViewModel = CommonServiceLocator.ServiceLocator.Current.GetInstance<PersonCenterViewModel>();
            //PersonViewModel.ErrorMsg.ForgotValidationCodeError = "";
        }

        private void QQjb_Click(object sender, RoutedEventArgs e)
        {
            YCButton yCButton = sender as YCButton;
            if (yCButton.Content.ToString() == "解绑")
            {
                msgBox.Visibility = Visibility.Visible;
                if (getValidationCodeBtn2 == null)
                    getValidationCodeBtn2 = CommonMethods.FindVisualChildItem<Button>(getVCode22);
                if (getValidationCodeBtn2 != null && getValidationCodeBtn2.Content.ToString() == "获取验证码")
                {
                    PersonCenterViewModel personViewModel = DataContext as PersonCenterViewModel;
                    personViewModel.BDType = 2;
                    getValidationCodeBtn2.Command = personViewModel.RelieveBindCommand;
                    getValidationCodeBtn2.CommandParameter = "3";
                }
            }
            else
            {
                string url = personViewModel1.QQLogin();
                ShowQQLogin showQQLogin = new ShowQQLogin();
                showQQLogin.LoadType = 1;
                showQQLogin.DataContext = personViewModel1;
                showQQLogin.loadUrl = url;
                showQQLogin.ShowDialog();
            }


        }

        private void WXjb_Click(object sender, RoutedEventArgs e)
        {
            YCButton yCButton = sender as YCButton;
            if (yCButton.Content.ToString() == "解绑")
            {
                PersonCenterViewModel personViewModel = DataContext as PersonCenterViewModel;
                personViewModel.UnBandingVisibility = Visibility.Visible;

                if (getValidationCodeBtn3 == null)
                    getValidationCodeBtn3 = CommonMethods.FindVisualChildItem<Button>(getVCode22);
                if (getValidationCodeBtn3 != null && getValidationCodeBtn3.Content.ToString() == "获取验证码")
                {

                    personViewModel.BDType = 3;
                    getValidationCodeBtn3.Command = personViewModel.RelieveBindCommand;
                    getValidationCodeBtn3.CommandParameter = "3";
                }
            }
            else
            {
                string url = personViewModel1.WXLogin();
                ShowQQLogin showQQLogin = new ShowQQLogin();
                showQQLogin.LoadType = 3;
                showQQLogin.DataContext = personViewModel1;
                showQQLogin.loadUrl = url;
                showQQLogin.ShowDialog();
            }
        }

        private void hideMessageBtn_Click(object sender, RoutedEventArgs e)
        {
            msgBox.Visibility = Visibility.Collapsed;
        }

        public void ShowImg(string url)
        {
            //webBrowser.ScriptErrorsSuppressed = true;
            // webBrowser.Navigate(url);
            ShowQQLogin showQQLogin = new ShowQQLogin();
            showQQLogin.LoadType = 1;
            showQQLogin.DataContext = personViewModel1;
            showQQLogin.loadUrl = url;
            showQQLogin.ShowDialog();

        }
        public void ShowQQImg(string url)
        {

            //webBrowser.Navigate(url);
            ShowQQLogin showQQLogin = new ShowQQLogin();
            showQQLogin.LoadType = 1;
            showQQLogin.loadUrl = url;
            showQQLogin.DataContext = personViewModel1;
            showQQLogin.ShowDialog();

        }


        private void YCButton_Click_2(object sender, RoutedEventArgs e)
        {
            PersonCenterViewModel personViewModel = DataContext as PersonCenterViewModel;
            personViewModel.xgmmVisibility = Visibility.Visible;
            if (getValidationCodeBtn == null)
                getValidationCodeBtn = CommonMethods.FindVisualChildItem<Button>(validationCode3);
            if (getValidationCodeBtn != null && getValidationCodeBtn.Content.ToString() == "获取验证码")
            {

                getValidationCodeBtn.Command = personViewModel.FogotPasswordCommand;
                getValidationCodeBtn.CommandParameter = "3";
            }
        }

        private void hideMessageBtn2_Click(object sender, RoutedEventArgs e)
        {
            msgBox2.Visibility = Visibility.Collapsed;
        }

        private void QQjb_Click_1(object sender, RoutedEventArgs e)
        {

        }

        private void SJjb_Click(object sender, RoutedEventArgs e)
        {
            YCButton yCButton = sender as YCButton;
            if (yCButton.Content.ToString() == "解绑")
            {
                PersonCenterViewModel personViewModel = DataContext as PersonCenterViewModel;
                personViewModel.UnBandingVisibility = Visibility.Visible;


                if (getValidationCodeBtn4 == null)
                    getValidationCodeBtn4 = CommonMethods.FindVisualChildItem<Button>(getVCode22);
                if (getValidationCodeBtn4 != null && getValidationCodeBtn4.Content.ToString() == "获取验证码")
                {

                    personViewModel.BDType = 1;
                    getValidationCodeBtn4.Command = personViewModel.RelieveBindCommand;
                    getValidationCodeBtn4.CommandParameter = "3";
                }
            }
            else
            {
                PersonCenterViewModel personViewModel = DataContext as PersonCenterViewModel;
                personViewModel.sjbdVisibility = Visibility.Visible;

                if (getValidationCodeBtn5 == null)
                    getValidationCodeBtn5 = CommonMethods.FindVisualChildItem<Button>(sjbdgetVCode);
                if (getValidationCodeBtn5 != null && getValidationCodeBtn5.Content.ToString() == "获取验证码")
                {

                    personViewModel.BDType = 0;
                    getValidationCodeBtn5.Command = personViewModel.BindCommand;
                    getValidationCodeBtn5.CommandParameter = "3";
                }


            }
        }

        private void YCButton_Click_1(object sender, RoutedEventArgs e)
        {
            //var subjetList= KMComBox.selectedCheckList;
            //var ClassList = treeView.ClassModellist;
            // personViewModel1.selectedCategory = subjetList ;
            // personViewModel1.selectedClass2 = new ObservableCollection<ClassModel2>(ClassList.ToList()) ;


        }

        private void hideMessageBtn3_Click(object sender, RoutedEventArgs e)
        {
            sjbdmsgBox.Visibility = Visibility.Collapsed;
        }
    }
}
